package com.soap.desensitize.factory.encry.json;

import com.soap.desensitize.encry.rreversible.symmetry.AbstractSymmetryEncry;
import com.soap.desensitize.exception.factory.StrategyFactoryException;
import com.soap.desensitize.factory.encry.EStrategy;
import com.soap.desensitize.strategy.rreversible.symmetry.AesStrategy;

/**
 * @desc 可逆不对称加密策略的工厂
 */
public class JsonFactory {
    /**
     * @desc 根据Class 生产策略
     * @param cla
     * @return
     * @throws InstantiationException
     * @throws IllegalAccessException
     */
    public static AbstractSymmetryEncry create(Class<? extends AbstractSymmetryEncry> cla) throws InstantiationException, IllegalAccessException {
        return cla.newInstance();
    }

    /**
     * @desc 根据类路径生产策略
     * @param classStr 策略类路径
     * @return
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws StrategyFactoryException
     */
    public static AbstractSymmetryEncry create(String classStr) throws InstantiationException, IllegalAccessException, StrategyFactoryException {
        switch (classStr){
            case "com.rj.bd.strategy.rreversible.symmetry.AesStrategy":
                return AesStrategy.getInstance();
            case "com.rj.bd.strategy.rreversible.symmetry.DesStrategy":
                return AesStrategy.getInstance();
            case "com.rj.bd.strategy.rreversible.symmetry.NumStrategy":
                return AesStrategy.getInstance();
            case "com.rj.bd.strategy.rreversible.symmetry.Rc4Strategy":
                return AesStrategy.getInstance();
            case "com.rj.bd.strategy.rreversible.symmetry.ThreeDesStrategy":
                return AesStrategy.getInstance();
        }
        throw new StrategyFactoryException("没有找到这个策略 "+classStr);
    }

    /**
     * @desc 根据类路径生产策略
     * @param eStrategy 策略类枚举
     * @return
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws StrategyFactoryException
     */
    public static AbstractSymmetryEncry create(EStrategy eStrategy) throws InstantiationException, IllegalAccessException, StrategyFactoryException {
        return create(eStrategy.getClassName());
    }

}
